package com.kerbores.shiro.utils;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.nutz.lang.Lang;

/**
 * shiro 密码验证规则
 * 
 * @author 王贵源
 * @email kerbores@kerbores.com
 *
 *        create at 2015年10月20日 下午12:04:20
 */
public class KerboresMD5CredentialsMatcher extends SimpleCredentialsMatcher {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.shiro.authc.credential.SimpleCredentialsMatcher#doCredentialsMatch
	 * (org.apache.shiro.authc.AuthenticationToken,
	 * org.apache.shiro.authc.AuthenticationInfo)
	 */
	@Override
	public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
		Object tokenCredentials = Lang.md5(String.valueOf(token.getPassword()));// 最简单的MD5加密
		Object accountCredentials = getCredentials(info);
		return equals(tokenCredentials, accountCredentials);
	}
}
